﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Text.RegularExpressions;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        /// <summary>
        /// 商品内容标签
        /// </summary>
        /// <returns></returns>
        public string ProductContent()
        {
            string mystyle = this.Label_Inserted;//标签显示内容
            string NameLength = this.GetParamValue("YX:StairCharacter");
            string WhetherOmit = this.GetParamValue("YX:WhetherOmit");
            string str_ShowIdentifier = this.GetParamValue("YX:ShowIdentifier");
            string ProID = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
            if (ProID == "")
            {
                return string.Empty;
            }

            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            if (!string.IsNullOrEmpty(ProID))
            {
                if (!ChangeHope.Common.ValidateHelper.IsNumber(ProID))
                {
                    return string.Empty;
                }
                YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
                YXShop.Model.Product.ProductInfo model = bll.GetModel(Convert.ToInt32(ProID));

                if (model == null)
                {
                    return string.Empty;
                }
                //修改点击次数
                bll.Amend(Convert.ToInt32(ProID), "pro_OnClicks", Convert.ToInt32(model.pro_OnClicks) + 1);
                string strContent = mystyle;

                #region 扩展属性
                string pattern = @"\{\#[\s\S]*?\#\}";
                string tempfinallyconent = strContent;
                StringBuilder GetTemp = new StringBuilder();
                MatchCollection macths = Regex.Matches(tempfinallyconent, pattern);
                string Str_Tag = "";
                string temptag = "";
                foreach (Match macth in macths)
                {
                    temptag = macth.ToString();
                    int templength = temptag.ToString().IndexOf("{#") + 2;
                    int templength2 = temptag.ToString().IndexOf("#}");
                    if (temptag.ToString().Substring(templength, templength2 - templength).ToString() != null)
                    {
                        Str_Tag = temptag.ToString().Substring(templength, templength2 - templength);
                    }
                }
                if (temptag != "")
                {
                    StringBuilder propertyShtml = new StringBuilder();
                    string extendName = "";
                    string extendValue = "";
                    if (model.pro_Type > 0)
                    {
                        YXShop.BLL.Product.ProductType productTypeBll = new YXShop.BLL.Product.ProductType();
                        if (model.pro_Property != "")
                        {
                            Regex groupSpace = new Regex(@"gro_space");
                            Regex valueSpace = new Regex(@"va_space");
                            string[] strProperty = groupSpace.Split(model.pro_Property);
                            foreach (string pv in strProperty)
                            {
                                string extendContent = Str_Tag;
                                extendValue = "";
                                if (!string.IsNullOrEmpty(pv.Trim()))
                                {
                                    string[] strSingleProperty = valueSpace.Split(pv);
                                    if (strSingleProperty[0] != "")
                                    {
                                        List<YXShop.Model.Product.ProductTypeProperty> list = productTypeBll.GetProductPropertyAllByWhere(model.pro_Type, "Id=" + strSingleProperty[0]);
                                        if (list.Count > 0)
                                        {
                                            if (strSingleProperty.Length > 1)
                                            {
                                                extendName = list[0].PropertyName;
                                                string[] strSingleProperty2 = strSingleProperty[1].Split(',');
                                                for (int p = 0; p < strSingleProperty2.Length; p++)
                                                {
                                                    extendValue += strSingleProperty2[p] + "&nbsp;&nbsp;";
                                                }
                                            }
                                        }
                                    }
                                    if (extendName != "")
                                    {
                                        if (extendContent.Contains("[#Extend_Name]"))
                                        {
                                            extendContent = extendContent.Replace("[#Extend_Name]", extendName);
                                        }
                                        if (extendContent.Contains("[#Extend_Value]"))
                                        {
                                            extendContent = extendContent.Replace("[#Extend_Value]", extendValue);
                                        }
                                        propertyShtml.Append(extendContent);
                                    }
                                }
                            }

                        }
                    }
                    if (Str_Tag != "")
                    {
                        if (propertyShtml.ToString() != string.Empty)
                        {
                            strContent = strContent.Replace(temptag, propertyShtml.ToString());
                        }
                        else
                        {
                            strContent = strContent.Replace(temptag, "");
                        }
                    }

                }

                #endregion

                #region 商品信息替换
                double price = Convert.ToDouble(model.pro_ShopPrice.ToString());
                string memberPrice = model.pro_RatingDiscount;
                string specificationValue = "";
                int productStock = Convert.ToInt32(model.pro_Stock.ToString());
                if (!string.IsNullOrEmpty(model.pro_Specifications))
                {
                    YXShop.BLL.Product.ProductSpecification proSpe = new YXShop.BLL.Product.ProductSpecification();
                    List<YXShop.Model.Product.ProductSpecification> proSpeList = proSpe.GetSpecification(Convert.ToInt32(model.pro_ID));
                    if (proSpeList.Count > 0)
                    {
                        price = Convert.ToDouble(proSpeList[0].SalePrice);
                        memberPrice = proSpeList[0].MemberPrice;
                        specificationValue = proSpeList[0].Specifications;
                        productStock = proSpeList[0].ProductStock;
                    }
                }
                if (HttpContext.Current.Session["MemberID"] != null && !string.IsNullOrEmpty(memberPrice.Trim()))
                {
                    price =YXShop.Common.ProductInfo.DiscountedPrice(int.Parse(HttpContext.Current.Session["MemberID"].ToString()), price, memberPrice);
                }

                if (strContent.IndexOf("[#Product_Name]") > -1)//商品名称
                {
                    string specVa = "";
                    if (specificationValue != "")
                    {
                        specVa = "[" + specificationValue + "]";
                    }
                    strContent = strContent.Replace("[#Product_Name]", model.pro_Name);//商品名称

                }
                if (strContent.IndexOf("[#Product_URL]") > -1)//商品URL
                {
                    string Url = Common.UrlStr("productcontent", "q_productid=" + model.pro_ID + "", "product/");
                    strContent = strContent.Replace("[#Product_URL]", Url);
                }
                if (strContent.IndexOf("[#Product_Key]") > -1)
                {
                    if (model.pro_KeyWord != null)
                    {

                        strContent = strContent.Replace("[#Product_Key]", model.pro_KeyWord);//关键字
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Key]", "");//关键字
                    }
                }
                if (strContent.IndexOf("[#Product_OnClick]") > -1)
                {
                    strContent = strContent.Replace("[#Product_OnClick]", model.pro_OnClicks.ToString());
                }

                if (strContent.IndexOf("[#Product_Introduction]") > -1)
                {
                    if (model.pro_Synopsis != null)
                    {
                        strContent = strContent.Replace("[#Product_Introduction]", model.pro_Synopsis);//商品简介
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Introduction]", "");//商品简介
                    }
                }
                if (strContent.IndexOf("[#Product_ShopPrice]") > -1)
                {
                    if (model.pro_ShopPrice != null)
                    {
                        strContent = strContent.Replace("[#Product_ShopPrice]", "<label id=\"productShopPrice\">" + price.ToString("f2") + "</label>");//商品
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_ShopPrice]", "");//商品商城价
                    }
                }
                if (strContent.IndexOf("[#Product_MarketPrice]") > -1)
                {

                    if (model.pro_MarketPrice != null)
                    {
                        strContent = strContent.Replace("[#Product_MarketPrice]", "<del>" + Convert.ToDouble(model.pro_MarketPrice).ToString("f2") + "</del>");//商品市场价
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_MarketPrice]", "");//商品市场价
                    }
                }
                if (strContent.IndexOf("[#Product_Thumbnails]") > -1)
                {
                    if (model.pro_Thumbnail != null)
                    {
                        strContent = strContent.Replace("[#Product_Thumbnails]", sp.DummyPaht + model.pro_Thumbnail);//商品缩略图
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Thumbnails]", "");//商品缩略图
                    }
                }
                if (strContent.IndexOf("[#Product_Bigmap]") > -1)//商品大图
                {
                    if (model.pro_Original != null)
                    {
                        strContent = strContent.Replace("[#Product_Bigmap]", sp.DummyPaht + model.pro_Original);//商品大图
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Bigmap]", "");
                    }
                }
                if (strContent.IndexOf("[#Product_Album]") > -1)
                {
                    bool isSpecification = false;
                    if (!string.IsNullOrEmpty(model.pro_Specifications.Trim()))
                    {
                        isSpecification = true;
                    }
                    strContent = strContent.Replace("[#Product_Album]", YXShop.TemplateAction.Common.ProductAlbum(ProID, model.pro_Name, model.pro_Images, model.pro_Original, isSpecification, 0));
                }
                if (strContent.IndexOf("[#Product_Content]") > -1)//商品详细信息
                {
                    if (model.pro_Content != null)
                    {
                        strContent = strContent.Replace("[#Product_Content]", model.pro_Content);//商品详细信息
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Content]", "");
                    }
                }

                if (strContent.IndexOf("[#Product_Code]") > -1)
                {
                    if (model.pro_NO != null)
                    {
                        strContent = strContent.Replace("[#Product_Code]", "<label id=\"productCoodsNo\">" + model.pro_NO + "</label>");//商品编码
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Code]", "");
                    }
                }
                if (strContent.IndexOf("[#Product_Weight]") > -1)
                {
                    if (model.pro_Weight != null)
                    {
                        strContent = strContent.Replace("[#Product_Weight]", model.pro_Weight.ToString());//商品重量
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Weight]", "0");//商品重量
                    }
                }
                if (strContent.IndexOf("[#Product_Units]") > -1)
                {
                    if (model.pro_WeightUnit != null)
                    {
                        string unitname = model.pro_WeightUnit == 1 ? "千克" : "克";
                        strContent = strContent.Replace("[#Product_Units]", unitname);//商品重量单位
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Units]", "");//商品重量单位
                    }
                }
                if (strContent.IndexOf("[#Product_Stock]") > -1)
                {
                    if (model.pro_Stock != null)
                    {
                        strContent = strContent.Replace("[#Product_Stock]", "<label id=\"productStock\">" + productStock.ToString() + "</label>");//商品库存
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_Stock]", "");//商品库存
                    }
                }
                if (strContent.IndexOf("[#Product_Integral]") > -1)
                {
                    strContent = strContent.Replace("[#Product_Integral]", "<label id=\"productIntegralPrice\">" + model.pro_DonateIntegral.ToString() + "</label>");//商品积分
                }
                if (strContent.IndexOf("[#Product_Point]") > -1)
                {
                    strContent = strContent.Replace("[#Product_Point]", "<label id=\"productPoint\">" + model.pro_IntegralPrice.ToString() + "</label>");//商品可使用点券
                }
                if (strContent.IndexOf("[#Product_SaleNum]") > -1)
                {
                    if (model.pro_Stock != null)
                    {
                        strContent = strContent.Replace("[#Product_SaleNum]", model.pro_SaleNum.ToString());//销售累计
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_SaleNum]", "");
                    }
                }

                if (strContent.IndexOf("[#Product_ShelvesCount]") > -1)
                {
                    if (model.pro_AuditCount != null)
                    {
                        strContent = strContent.Replace("[#Product_ShelvesCount]", model.pro_AuditCount.ToString());//商品上架数量
                    }
                    else
                    {
                        strContent = strContent.Replace("[#Product_ShelvesCount]", "");//商品上架数量
                    }
                }

                if (strContent.Contains("[#Product_Specifications]"))
                {
                    StringBuilder specStr = new StringBuilder();
                    if (!string.IsNullOrEmpty(model.pro_Specifications.Trim()))
                    {
                        string specialSpec = "";
                        if (!string.IsNullOrEmpty(model.pro_Specialspecifications))
                        {
                            Regex ssSpace = new Regex(@"s_spacebar");
                            string[] ssv = ssSpace.Split(model.pro_Specialspecifications);
                            specialSpec = ssv[0];
                            specStr.Append("<div class=\"div_Specifications\">\r\n");
                            specStr.Append("<ul>\r\n");
                            specStr.Append("<li class=\"li_Specifications_Name\">" + specialSpec + "：<span id=\"SpecificationsValue0\">未选择</span></li>\r\n");
                            specStr.Append("</ul>\r\n");
                            specStr.Append("<ul>\r\n");
                            string specialVa = ssv[1];
                            string[] specialVaArr = specialVa.Replace("\r\n", "\n").Split('\n');
                            for (int s = 0; s < specialVaArr.Length; s++)
                            {
                                string seletedStyle = "Special_SpecificationsSeleted";
                                YXShop.BLL.Product.ProductAlbum proAlbum = new YXShop.BLL.Product.ProductAlbum();
                                DataTable proAlbumdt = proAlbum.GetProAlbumAll(model.pro_ID, s, 1);
                                if (proAlbumdt.Rows.Count > 0)
                                {
                                    string addPath = proAlbumdt.Rows[0]["originaladdress"].ToString();
                                    string speValueName = specialVaArr[s];
                                    string toneContent = string.Empty;
                                    if (addPath.Contains("#"))
                                    {
                                        toneContent = "<p style=\"background-color:" + addPath + "\" title=\"" + speValueName + "\"></p>";
                                    }
                                    else
                                    {
                                        toneContent = "<img src=\"" + sp.DummyPaht + addPath + "\" border=\"0\" alt=\"" + speValueName + "\" />";
                                    }
                                    string specifications = ChangeHope.WebPage.PageRequest.GetString("spe");
                                    string speUrl = Common.UrlStr("productcontent", "q_productid=" + model.pro_ID + ";spe=", "product/");
                                    specStr.Append("<li class=\"" + seletedStyle + "\" id=\"SpeProperty_0_" + s + "\" onclick=\"Specifications('" + sp.DummyPaht + "',this.id,0," + s + "," + model.pro_ID + ",true," + specialVaArr.Length + ",'" + speValueName + "');\" onmouseout=\"Alumb()\" style=\"cursor:hand\">" + toneContent + "</li>\r\n");
                                }
                            }
                            specStr.Append("</ul>\r\n");
                            specStr.Append("</div>\r\n");
                        }

                        Regex gSpace = new Regex(@"g_space");
                        string[] gsv = gSpace.Split(model.pro_Specifications);
                        for (int g = 0; g < gsv.Length; g++)
                        {
                            string seletedStyle = "SpecificationsSeleted";
                            if (!string.IsNullOrEmpty(gsv[g].Trim()))
                            {
                                Regex nvSpace = new Regex(@"n_v_space");
                                string[] nvsv = nvSpace.Split(gsv[g]);
                                if (nvsv[0].Trim() != specialSpec.Trim())
                                {
                                    Regex vaRegex = new Regex(@"\r\n");
                                    string[] speVa = vaRegex.Split(nvsv[1]);
                                    specStr.Append("<div class=\"div_Specifications\">\r\n");
                                    specStr.Append("<ul>\r\n");
                                    specStr.Append("<li class=\"li_Specifications_Name\">" + nvsv[0] + "：<span id=\"SpecificationsValue" + g + "\">未选择</span></li>\r\n");
                                    specStr.Append("</ul>\r\n");
                                    specStr.Append("<ul>\r\n");
                                    for (int n = 0; n < speVa.Length; n++)
                                    {
                                        specStr.Append("<li class=\"" + seletedStyle + "\"  id=\"SpeProperty_" + g + "_" + n + "\" onclick=\"Specifications('" + sp.DummyPaht + "',this.id," + g + "," + n + "," + model.pro_ID + ",false," + speVa.Length + ",'" + speVa[n] + "')\" style=\"cursor:hand\"><p>" + speVa[n] + "</p></li>\r\n");
                                    }
                                    specStr.Append("</ul>\r\n");
                                    specStr.Append("</div>\r\n");
                                }
                            }
                        }
                    }
                    strContent = strContent.Replace("[#Product_Specifications]", specStr.ToString());
                }

                if (strContent.Contains("[#Buy_Statistics]"))
                {
                    Regex gSpace = new Regex(@"g_space");
                    string[] gsv = gSpace.Split(model.pro_Specifications);
                    StringBuilder buyStatistics = new StringBuilder();
                    buyStatistics.Append("<div class=\"BuyStatistics\">\r\n");
                    buyStatistics.Append("<div class=\"buyStatistics_Count\">\r\n");
                    buyStatistics.Append("<span>");
                    buyStatistics.Append("<input type=\"hidden\" name=\"hidProductStock\" id=\"hidProductStock\" value=\"" + model.pro_Stock + "\"/>");
                    buyStatistics.Append("<input type=\"hidden\" name=\"SpecificationsGroup\" id=\"SpecificationsGroup\" value=\"" + gsv.Length + "\"/>数量：</span><input name=\"ProductCount\" type=\"text\" id=\"ProductCount\" value=\"1\" size=\"8\"  onblur=\"productTotalPrice(this.value)\" onkeyup=\"value=value.replace(/[^\\d]/g,'')\"/>\r\n");
                    buyStatistics.Append("</div>\r\n");
                    buyStatistics.Append("<div class=\"buyStatistics_Info\">\r\n");
                    for (int b = 0; b < gsv.Length; b++)
                    {
                        if (!string.IsNullOrEmpty(gsv[b].Trim()))
                        {
                            Regex nvSpace = new Regex(@"n_v_space");
                            string[] nvsv = nvSpace.Split(gsv[b]);
                            buyStatistics.Append("<p><strong><label id=\"SpecificationsTitle" + b + "\">" + nvsv[0] + "</label>：<span id=\"SpecificationsValueMake" + b + "\">未选择</span></strong></p>\r\n");
                        }

                    }
                    buyStatistics.Append("<p><input type=\"hidden\" name=\"productUnitPrice\" id=\"productUnitPrice\" value=\"" + price + "\"/><strong>小计：￥<span id=\"productPriceTotal\">" + price + "</span></strong></p>\r\n");
                    buyStatistics.Append("</div>\r\n");
                    buyStatistics.Append("<div class=\"buyStatistics_Button\">\r\n");
                    buyStatistics.Append("<img style=\"cursor:hand\" src=\"" + sp.DummyPaht + "images/btn_cart.gif\" border='0' onclick=\"AddCarShop('" + sp.DummyPaht + "'," + model.pro_ID + ")\">");
                    buyStatistics.Append("</div>\r\n");
                    buyStatistics.Append("</div>\r\n");
                    strContent = strContent.Replace("[#Buy_Statistics]", buyStatistics.ToString());
                }
                string SellModel = "";
                //商品出售方式（1：只能使用现金购买；2：只能使用积分购买；3：现金或积分均可）
                if (model.pro_SaleType == 1)
                {
                    SellModel = "现金购买";

                }
                else if (model.pro_SaleType == 2)
                {
                    SellModel = "积分购买";
                }
                else if (model.pro_SaleType == 3)
                {
                    SellModel = "现金或积分均可";
                }
                if (strContent.IndexOf("[#Product_SellWay]") > -1)
                {
                    strContent = strContent.Replace("[#Product_SellWay]", SellModel);
                }
                //商品详细信息
                if (strContent.IndexOf("[#Product_ParticularInfo]") > -1)
                {
                    StringBuilder parameterShtml = new StringBuilder();
                    if (model.pro_Type > 0)
                    {
                        YXShop.BLL.Product.ProductType parameterTypeBll = new YXShop.BLL.Product.ProductType();
                        if (model.pro_Parameters != "")
                        {

                            Regex groupSpace = new Regex(@"t_space");
                            Regex tIdSpace = new Regex(@"tid_space");
                            string[] strParameterGroup = groupSpace.Split(model.pro_Parameters);
                            foreach (string par in strParameterGroup)
                            {
                                if (par != "")
                                {
                                    string[] strParameter = tIdSpace.Split(par);
                                    if (strParameter[0] != "")
                                    {
                                        YXShop.Model.Product.ProductTypeParameter parameterTypeModel = parameterTypeBll.GetProductParameterModel(Convert.ToInt32(strParameter[0]), Convert.ToInt32(model.pro_Type));
                                        if (parameterTypeModel != null)
                                        {
                                            parameterShtml.Append("<ul>");
                                            parameterShtml.Append("<h1>" + parameterTypeModel.ParameterName + "</h1>");
                                            string[] strParameterValueGroup = strParameter[1].Split('|');
                                            foreach (string pvg in strParameterValueGroup)
                                            {
                                                string[] strParameterValue = pvg.Split(',');
                                                if (strParameterValue[0] != "")
                                                {
                                                    YXShop.Model.Product.ProductTypeParameter parameterModel = parameterTypeBll.GetProductParameterModel(Convert.ToInt32(strParameterValue[0]), Convert.ToInt32(model.pro_Type));
                                                    if (parameterModel != null)
                                                    {
                                                        parameterShtml.Append("<li>");
                                                        parameterShtml.Append("<span>" + parameterModel.ParameterName + "：</span>");
                                                        for (int v = 1; v < strParameterValue.Length; v++)
                                                        {
                                                            parameterShtml.Append(strParameterValue[v]);
                                                        }
                                                        parameterShtml.Append("</li>");
                                                    }

                                                }
                                            }
                                            parameterShtml.Append("</ul>");
                                        }
                                    }
                                }

                            }
                        }
                    }
                    strContent = strContent.Replace("[#Product_ParticularInfo]", parameterShtml.ToString());
                }
                //商品相关文章
                if (strContent.IndexOf("[#CorrelationArticle]") > -1 && !string.IsNullOrEmpty(model.pro_RelatingArtID))
                {
                    StringBuilder articleShtml = new StringBuilder();
                    YXShop.BLL.SystemInfo.Article articlebll = new YXShop.BLL.SystemInfo.Article();
                    ChangeHope.DataBase.DataByPage articledb = articlebll.GetList(" and Id in (" + model.pro_RelatingArtID + ")");
                    if (articledb.DataReader != null)
                    {
                        while (articledb.DataReader.Read())
                        {
                            string articleUrl = string.Empty;
                            if (articledb.DataReader["LinkUrl"].ToString() != "")
                            {
                                articleUrl = articledb.DataReader["LinkUrl"].ToString();
                            }
                            else
                            {
                                string ChannelId = articledb.DataReader["Channel"].ToString();
                                if (ChannelId.Length > 2)
                                {
                                    ChannelId = ChannelId.Substring(0, 3);
                                }
                                articleUrl = YXShop.TemplateAction.Common.UrlStr("articlecontent", "q_ChannelId=" + ChannelId + ";Id=" + articledb.DataReader["Id"].ToString() + "", "article/");
                            }
                            articleShtml.Append("<li><a href='" + articleUrl + "'>" + articledb.DataReader["Title"].ToString() + "</a></li>");
                        }
                    }
                    strContent = strContent.Replace("[#CorrelationArticle]", articleShtml.ToString());
                }
                else
                {
                    strContent = strContent.Replace("[#CorrelationArticle]", "");
                }
                //相关商品
                if (strContent.IndexOf("[#Product_Correlation]") > -1)
                {
                    StringBuilder RelatingProductshtml = new StringBuilder();
                    ChangeHope.DataBase.DataByPage relatingproduct = bll.GetList(" [order by] pro_ID asc", 10, " and pro_ID in (" + model.pro_RelatingproID + ")");
                    if (!string.IsNullOrEmpty(model.pro_RelatingproID) || model.pro_RelatingproID != null)
                    {

                        if (relatingproduct.DataReader != null)
                        {
                            int Length = 8;
                            bool omit = false;
                            if (!string.IsNullOrEmpty(NameLength))
                            {
                                if (ChangeHope.Common.ValidateHelper.IsNumber(NameLength) && NameLength != "0")
                                {
                                    Length = Convert.ToInt32(NameLength);
                                }
                            }
                            if (!string.IsNullOrEmpty(WhetherOmit) && (WhetherOmit == "true" || WhetherOmit == "false"))
                            {
                                omit = Convert.ToBoolean(WhetherOmit);
                            }
                            string endstr = string.Empty;
                            if (omit)
                            {
                                endstr = "...";
                            }
                            while (relatingproduct.DataReader.Read())
                            {
                                double relatingProductPrice = double.Parse(relatingproduct.DataReader["pro_ShopPrice"].ToString());
                                if (HttpContext.Current.Session["MemberID"] != null)
                                {
                                    relatingProductPrice = YXShop.Common.ProductInfo.DiscountedPrice(Convert.ToInt32(HttpContext.Current.Session["MemberID"].ToString()), relatingProductPrice, model.pro_RatingDiscount);
                                }
                                string Url = string.Empty;
                                Url = Common.UrlStr("productcontent", "q_productid=" + relatingproduct.DataReader["pro_ID"].ToString() + "", "product/");
                                RelatingProductshtml.Append("<ul class='RelatingProduct'>");
                                RelatingProductshtml.Append("<li class='RelatingProductImages'><a href=\"" + sp.DummyPaht + Url + "\"><img onerror = \"this.src='" + sp.DummyPaht + "images/none_50.gif'\" src=\"" + sp.DummyPaht + relatingproduct.DataReader["pro_Thumbnail"].ToString() + "\" border='0'/></a></li>");
                                RelatingProductshtml.Append("<li class='RelatingProductName'><a href=\"" + Url + "\">" + ChangeHope.Common.StringHelper.SubStringAndAppend(relatingproduct.DataReader["pro_Name"].ToString(), Length, endstr) + "</a></li>");
                                RelatingProductshtml.Append("<li><span style='color:#FF0000'>商城售价：<span style='font-weight:bold;'>￥" + relatingProductPrice + "</span></span></li>");
                                RelatingProductshtml.Append("</ul>");
                            }
                        }
                    }
                    strContent = strContent.Replace("[#Product_Correlation]", RelatingProductshtml.ToString());
                }
                #endregion

                #region 拍卖
                if (str_ShowIdentifier == "5")
                {
                    YXShop.BLL.Product.ProductAuction pabll = new YXShop.BLL.Product.ProductAuction();
                    YXShop.Model.Product.ProductAuction pamodel = pabll.GetModelProductID(Convert.ToInt32(ProID));

                    YXShop.BLL.Product.Product_Auction_Bid pabbll = new YXShop.BLL.Product.Product_Auction_Bid();
                    string maxPrice = pabbll.maxValues("price", ProID);
                    string AuctionName = string.Empty;
                    string StartTime = string.Empty;
                    string EndTime = string.Empty;
                    string Price = string.Empty;
                    string PriceRange = string.Empty;
                    string Deposit = string.Empty;
                    string Description = string.Empty;
                    if (pamodel != null)
                    {
                        AuctionName = pamodel.AuctionName;
                        StartTime = pamodel.StartTime.ToString();
                        EndTime = pamodel.EndTime.ToString();
                        Price = pamodel.Price.ToString();
                        PriceRange = pamodel.PriceRange.ToString();
                        Deposit = pamodel.Deposit.ToString();
                        Description = pamodel.Description;
                    }

                    if (strContent.IndexOf("[#Auction_Name]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_Name]", AuctionName);
                    }
                    if (strContent.IndexOf("[#Auction_StartTime]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_StartTime]", StartTime);
                    }
                    if (strContent.IndexOf("[#Auction_EndTime]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_EndTime]", EndTime);
                    }
                    if (strContent.IndexOf("[#Auction_StartPrice]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_StartPrice]", Price);
                    }
                    if (strContent.IndexOf("[#Auction_AddLevel]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_AddLevel]", PriceRange);
                    }
                    if (strContent.IndexOf("[#Auction_Deposit]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_Deposit]", Deposit);
                    }
                    if (strContent.IndexOf("[#Auction_Description]") > -1)
                    {
                        strContent = strContent.Replace("[#Auction_Description]", Description);
                    }
                    if (strContent.IndexOf("[#Auction_SurplusTime]") > -1)
                    {

                    }
                    if (strContent.IndexOf("[#Auction_CurrentPrice]") > -1)
                    {
                        string CurrentPrice = string.Empty;
                        if (!string.IsNullOrEmpty(maxPrice))
                        {
                            CurrentPrice = maxPrice;
                        }
                        else
                        {
                            CurrentPrice = Price;
                        }
                        strContent = strContent.Replace("[#Auction_CurrentPrice]", CurrentPrice);
                    }
                    if (strContent.IndexOf("[#Bid_Button]") > -1)
                    {
                        string Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/vendue.jpg\" border=\"0\">";
                        string HtmlUrl = Common.UrlStr("product_bid_info", "q_productid=" + ProID + "", "product/");
                        string Url = "<a href=\"" + HtmlUrl + "\">" + Image + "</a>";
                        if (Convert.ToDateTime(EndTime) < System.DateTime.Now)
                        {
                            Url = "<a href=\"#\" title='竞价结束'>" + Image + "</a>";
                        }
                        strContent = strContent.Replace("[#Bid_Button]", Url);
                    }
                }
                #endregion

                #region 团购参数
                if (str_ShowIdentifier == "3")
                {
                    YXShop.BLL.Product.Product_IntegratePurchas pipbll = new YXShop.BLL.Product.Product_IntegratePurchas();
                    YXShop.Model.Product.Product_IntegratePurchas pipmodel = pipbll.GetModelProductID(Convert.ToInt32(ProID));
                    string gbStartTime = string.Empty;
                    string gbEndTime = string.Empty;
                    string gbDeposit = string.Empty;
                    string gbBuyCount = string.Empty;
                    string gbDonateIntegral = string.Empty;
                    string gbPriceLevel = string.Empty;
                    string gbDescription = string.Empty;
                    if (pipmodel != null)
                    {
                        gbStartTime = pipmodel.StartTime.ToString();
                        gbEndTime = pipmodel.EndTime.ToString();
                        gbDeposit = pipmodel.Deposit.ToString();
                        gbBuyCount = pipmodel.Count.ToString();
                        gbDonateIntegral = pipmodel.DonateIntegral.ToString();
                        string[] LadderCount = pipmodel.LadderCount.Split(',');
                        string[] LadderPrice = pipmodel.LadderPrice.Split(',');
                        string ProductUnit = "";
                        if (model.pro_Unit.ToString() != "0")
                        {
                            ProductUnit = model.pro_Unit.ToString();
                        }
                        for (int l = 0; l < LadderCount.Length; l++)
                        {
                            gbPriceLevel += "团购数量达到：" + LadderCount[l] + ProductUnit + "，享受价格为：" + LadderPrice[l] + "<br>";
                        }
                        gbDescription = pipmodel.Description;

                    }
                    if (strContent.IndexOf("[#GroupBuy_StartTime]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_StartTime]", gbStartTime);

                    }
                    if (strContent.IndexOf("[#GroupBuy_EndTime]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_EndTime]", gbEndTime);
                    }
                    if (strContent.IndexOf("[#GroupBuy_Deposit]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_Deposit]", gbDeposit);
                    }
                    if (strContent.IndexOf("[#GroupBuy_BuyCount]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_BuyCount]", gbBuyCount);
                    }
                    if (strContent.IndexOf("[#GroupBuy_DonateIntegral]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_DonateIntegral]", gbDonateIntegral);
                    }
                    if (strContent.IndexOf("[#GroupBuy_PriceLevel]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_PriceLevel]", gbPriceLevel);
                    }
                    if (strContent.IndexOf("[#GroupBuy_Description]") > -1)
                    {
                        strContent = strContent.Replace("[#GroupBuy_Description]", gbDescription);
                    }
                }
                #endregion

                #region 操作按钮
                if (strContent.IndexOf("[#SendGroupBuy_Button]") > -1)
                {
                    string Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/rindZ.gif\" border=\"0\">";
                    string HtmlUrl = Common.UrlStr("product_sendgroupbuy_form", "q_productid=" + ProID + "", "product/");
                    string Url = "<a href=\"" + HtmlUrl + "\">" + Image + "</a>";
                    strContent = strContent.Replace("[#SendGroupBuy_Button]", Url);
                }
                if (strContent.IndexOf("[#GroupBuy_Button]") > -1)
                {
                    string GroupBuyImage = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/rindG.gif\" border=\"0\">";
                    string GroupBuyHtmlUrl = Common.UrlStr("product_groupbuyinfolist", "q_productid=" + ProID + "", "product/");
                    string GroupBuyUrl = "<a href=\"" + GroupBuyHtmlUrl + "\">" + GroupBuyImage + "</a>";
                    strContent = strContent.Replace("[#GroupBuy_Button]", GroupBuyUrl);
                }

                if (strContent.IndexOf("[#ShoppingCar_Button]") > -1)
                {
                    string Image = "<span id='adress'></span><img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/button_buy.gif\" onClick=\"showShopCart('showShopCart',document.getElementById('adress'),'',350,80," + ProID + ",'" + sp.DummyPaht + "','" + specificationValue + "');\" style='cursor:hand;' border=\"0\">";
                    if (productStock < 1)
                    {
                        Image = "<span id='adress'></span><img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/button_buy.gif\" style='cursor:hand;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);' border=\"0\"  title='库存不足'>";
                    }
                    strContent = strContent.Replace("[#ShoppingCar_Button]", Image);
                }
                if (strContent.IndexOf("[#Immediately_ShoppingCar]") > -1)
                {
                    string Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/Immediately_button_buy.gif\" border=\"0\">";
                    string HtmlUrl = Common.UrlStr("shoppingcart", "q_productid=" + ProID + ";q_proSpecification=" + specificationValue + "", "product/");
                    if (productStock < 1)
                    {
                        Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/Immediately_button_buy.gif\" border=\"0\" style='cursor:hand;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);' title='库存不足'>";
                        HtmlUrl = "#";
                    }
                    string Url = "<a href=\"" + HtmlUrl + "\">" + Image + "</a>";
                    strContent = strContent.Replace("[#Immediately_ShoppingCar]", Url);
                }
                if (strContent.IndexOf("[#Collection_Button]") > -1)
                {
                    string Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/button_sC.gif\" border=\"0\">";
                    string HtmlUrl = Common.UrlStr("collection", "q_productid=" + ProID + "", "filehandle/");
                    string Url = "<a href=\"" + HtmlUrl + "\">" + Image + "</a>";
                    strContent = strContent.Replace("[#Collection_Button]", Url);
                }
                if (strContent.IndexOf("[#Comments_Button]") > -1)
                {
                    string Image = "<img src=\"" + sp.DummyPaht + sp.WebSiteTemplatePath + "/images/button_pL.gif\" border=\"0\">";
                    string Url = "<a href=\"#Comment\">" + Image + "</a>";
                    strContent = strContent.Replace("[#Comments_Button]", Url);
                }
                #endregion
                return strContent;
            }
            else
            {
                return "!!!!!!!!!!!未传参数！";
            }
        }

    }

}
